package com.itany.shop.service.impl;

import com.itany.shop.dao.ProductDao;
import com.itany.shop.entity.Product;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.util.PageInfo;

import java.util.List;

/**
 * @author 石小俊
 * @date 2023年06月06日 15:50
 */
public class ProductServiceImpl implements ProductService {

    private ProductDao productDao = (ProductDao) ObjectFactory.getObject("productDao");

    @Override
    public List<Product> findAll() {
        List<Product> products = productDao.selectAll();
        return products;
    }

    @Override
    public PageInfo<Product> findPage(int pageNo, int pageSize) {
        // 获取数据总量
        int total = productDao.selectCount();
        // 获取当前页数据
        List<Product> products = productDao.selectPage(pageNo,pageSize);
        // 封装分页对象
        PageInfo<Product> pageProduct = new PageInfo<>(total,pageNo,pageSize,products);
        return pageProduct;
    }
}
